<!DOCTYPE html>
<!-- saved from url=(0065)https://ent.safe517.com/fdWebCompany/findView/replenish.into.into -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>食品安全追溯系统</title>

    <!--引入CSS-->
    <link rel="stylesheet" type="text/css" href="/static/ueditor/third-party/webuploader/webuploader.css">
    <!--引入JS-->
    <script src="/static/jquery/jquery-1.8.3.js" type="text/javascript"></script>
    <script type="text/javascript" src="/static/ueditor/third-party/webuploader/webuploader.js"></script>

    <!--<script src="/static/jinhuo/custome.js" type="text/javascript" charset="utf-8"></script>-->
    <script src="/static/jinhuo/jquery.form.js" type="text/javascript"></script>
    <!--<script src="/static/jinhuo/popup.js" type="text/javascript"></script>-->
    <script src="/static/jinhuo/common(1).js" type="text/javascript">
    </script>
    <script src="/static/jinhuo/common1.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/jinhuo/plupload.full.min.js" type="text/javascript"></script>
    <script src="/static/jinhuo/reAlert.js" type="text/javascript"></script>
    <link href="/static/jinhuo/common.css" rel="stylesheet" type="text/css">
    <link href="/static/jinhuo/style.css" rel="stylesheet" type="text/css">
    <!-- 图片查看 -->
    <script src="/static/jinhuo/jquery-rotate-2.3.min.js" type="text/javascript"></script>
    <script src="/static/jinhuo/jquery.ui.js" type="text/javascript"></script>
    <script src="/static/jinhuo/jquery.autocomplete.js" type="text/javascript"></script>
    <link href="/static/jinhuo/foximg.css" rel="stylesheet" type="text/css">
    <link href="/static/jinhuo/jquery.autocomplete.css" rel="stylesheet" type="text/css">
    <script src="/static/jinhuo/foximg.js" type="text/javascript" charset="utf-8"></script>

    <script>
        $(document).ready(function () {
            var uploader = WebUploader.create({

                // 选完文件后，是否自动上传。
                auto: true,

                // swf文件路径
                swf: '/static/ueditor/third-party/webuploader/Uploader.swf',

                // 文件接收服务端。
                server: '/user/upload',

                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: '#filePicker',
                multiple: false,

                // 只允许选择图片文件。
                accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png',
                    mimeTypes: 'image/*'
                }
            });

            uploader.on('fileQueued', function (file) {
                var $list = $("#fileList"),
                        $li = $(
                                '<div id="' + file.id + '" class="file-item thumbnail">' +
                                '<img>' +
                                '<div class="info">' + file.name + '</div>' +
                                '</div>'
                        ),
                        $img = $li.find('img');


                // $list为容器jQuery实例
                $list.append($li);

                // 创建缩略图
                uploader.makeThumb(file, function (error, src) {
                    if (error) {
                        $img.replaceWith('<span>不能预览</span>');
                        return;
                    }

                    $img.attr('src', src);
                }, 100, 100); //100x100为缩略图尺寸
            });

//            // 当有文件添加进来的时候
//            uploader.on('fileQueued', function (file) {
//                var $li = $(
//                                '<div id="' + file.id + '" class="file-item thumbnail">' +
//                                '<img>' +
//                                '<div class="info">' + file.name + '</div>' +
//                                '</div>'
//                        ),
//                        $img = $li.find('img');
//
//
//                // $list为容器jQuery实例
//                var $list = $("#fileList");
//                $list.append($li);
//
//                // 创建缩略图
//                // 如果为非图片文件，可以不用调用此方法。
//                // thumbnailWidth x thumbnailHeight 为 100 x 100
//                uploader.makeThumb(file, function (error, src) {
//                    if (error) {
//                        $img.replaceWith('<span>不能预览</span>');
//                        return;
//                    }
//
//                    $img.attr('src', src);
//                }, thumbnailWidth, thumbnailHeight);
//            });


            // 文件上传过程中创建进度条实时显示。
            uploader.on('uploadProgress', function (file, percentage) {
                var $li = $('#' + file.id),
                        $percent = $li.find('.progress span');

                // 避免重复创建
                if (!$percent.length) {
                    $percent = $('<p class="progress"><span></span></p>')
                            .appendTo($li)
                            .find('span');
                }

                $percent.css('width', percentage * 100 + '%');
            });

            // 文件上传成功，给item添加成功class, 用样式标记上传成功。
            uploader.on('uploadSuccess', function (file, response) {
                $('#' + file.id).addClass('upload-state-done');
                $('#pic').val($('#pic').val() + "," + response.fileName)
            });

            // 文件上传失败，显示上传出错。
            uploader.on('uploadError', function (file) {
                var $li = $('#' + file.id),
                        $error = $li.find('div.error');

                // 避免重复创建
                if (!$error.length) {
                    $error = $('<div class="error"></div>').appendTo($li);
                }

                $error.text('上传失败');
            });

            // 完成上传完了，成功或者失败，先删除进度条。
            uploader.on('uploadComplete', function (file) {
                $('#' + file.id).find('.progress').remove();
            });
        });
    </script>

    <style>
         .input_code{
            height: 36px!important;
        }
    </style>
</head>
<body>

<!--<script src="/static/jinhuo/lhgcore.lhgcalendar.min.js" type="text/javascript"></script>-->

<!--<script type="text/javascript" src="/static/jinhuo/jquery.autocomplete.js"></script>-->
<!--<link rel="Stylesheet" href="/static/jinhuo/jquery.autocomplete.css">-->


<div id="loading"
     style="position:absolute; top:50%; left:50%; margin:0 auto; height:300px; z-index: 888; display:none;">
    <img src="/static/jinhuo/loading.gif">
</div>
<div class="main_box">
    <div class="main_con">
        <!--<h3 class="process_title"><span>当前位置: </span><a-->
        <!--href="https://ent.safe517.com/fdWebCompany/findView/replenish.into.into">新增进货</a></h3>-->
        <!--<div class="query">-->
        <form data-url="${basePath}/${code}/save" method="post" class="form-horizontal" role="form">
            <table class="query_table" style="width:900px;">
                <tbody>
                <tr>
                    <!--<td class="td_lf"><em class="star">*</em>进货日期</td>-->
                    <!--<td><input type="text" class="input_date" id="date_into" name="buy.date" value=""-->
                               <!--readonly="readonly"></td>-->
                    <!--<script type="text/javascript">-->
                        <!--var mydateInput = document.getElementById("date_into");-->
                        <!--var date = new Date();-->
                        <!--var dateString = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();-->
                        <!--mydateInput.value = dateString;-->
                    <!--</script>-->
                    <td class="td_lf"><em class="star">&nbsp;</em>商品条码<span style="display:none;" id="code1"></span>
                    </td>
                    <td >
                        <input type="text" class="input_code ac_input" placeholder="请扫描商品条码" id="code" style="width:168px;">
                    </td>
                    <td class="td_lf"><em class="star">*</em><em id="circulationType1">采购品</em></td>
                    </td>
                    <td colspan="3">
                        <!--<input type="text" class="input_code ac_input" placeholder="点击选择供应商" autocomplete="off"-->
                               <!--id="supplierName" style="width:200px;">-->
                        <!--<input type="hidden" name="buy.supp_id" id="supplierId">-->
                        <input type="text" class="input_code ac_input" id="inputMatName" style="width:168px;"
                               placeholder="点击选择采购品" autocomplete="off">
                        <input type="text" id="inputMatId" name="buy.product_id" style="display:none">
                    </td>
                </tr>
                <tr>
                    <td class="td_lf"><em class="star">*</em><em id="circulationType3">供应商</em><span style="display:none;" id="productId"></span>

                    <td>
                        <input type="text" class="input_code ac_input" placeholder="选择供应商" autocomplete="off"
                               id="supplierName" style="width:200px;">
                        <input type="hidden" name="buy.supp_id" id="supplierId">

                    </td>
                    <td class="td_lf"><em class="star">*</em><em id="circulationType4">生产单位</em></td>
                    <td><input type="text" class="input_code" value="" autocomplete="" id="manufacture"
                               style="background:#e2e2e2;width:200px;" readonly="true"></td>
                    <!--<td class="td_lf"><em class="star">*</em><em id="circulationType2">生产日期</em></td>-->
                    <!--<td><input type="text" class="input_date" name="buy.product_date" id="date_prod" value=""></td>-->
                    <td class="td_lf"><em class="star"></em>产地</td>
                    <td><input type="text" class="input_code" autocomplete="" maxlength="50" id="placeOfPro" value=""
                               style="background:#e2e2e2;width:168px;" readonly="true"></td>
                </tr>
                <tr>
                    <td class="td_lf"><em class="star">*</em>规格</td>
                    <td><input type="text" class="input_code" id="spec" style="width:168px; background:#dcdddd;"
                               value="" readonly="true"></td>
                    <td class="td_lf"><em class="star">*</em>数量</td>
                    <td><input type="text" class="input_code" id="quantity" name="buy.num" value="" style="width:200px;"
                               maxlength="8">
                    </td>
                    <!--<td class="td_lf"><em class="star">&nbsp;</em>生产批号</td>-->
                    <!--<td><input type="text" class="input_code" id="productionBatch" name="buy.product_code" style="width:168px;" value=""-->
                    <!--maxlength="20"></td>-->
                    <!--<td class="td_lf"><em class="star"></em>产地</td>-->
                    <!--<td><input type="text" class="input_code" autocomplete="" maxlength="50" id="placeOfPro" value=""-->
                               <!--style="background:#e2e2e2;width:168px;" readonly="true"></td>-->
                </tr>
                <!--<tr>-->
                <!---->
                <!--&lt;!&ndash;<td class="td_lf"><em class="star"></em>追溯码</td>&ndash;&gt;-->
                <!--&lt;!&ndash;<td><input type="text" class="input_code" maxlength="50" id="traceCode" value=""&ndash;&gt;-->
                <!--&lt;!&ndash;style="width:200px;"></td>&ndash;&gt;-->
                <!--</tr>-->
                </tbody>
            </table>
            <input type="hidden" name="status" value="1">
            <input type="hidden" name="buy.buy_num" value="${buynum!}" id="buynum">
        </form>
        <input type="hidden" name="pic" id="pic" value="">
        <div id="uploader-demo" style="display: none;">
            <!--用来存放item-->
            <div id="fileList" class="uploader-list"></div>
            <div id="filePicker">上传该批产品检测报告</div>
        </div>
        <!--<div class="kuang" style="right:0; left:900px;bottom:130px; ">至少填写一项</div>-->
        <div style="text-align: left">
            <button type="button" class="btn btn-success" value="新增产品" id="btn_storage">添加到列表</button>
            &nbsp;&nbsp;
            <button type="button" class="btn btn-danger" value="提交审核" id="tjsh">提交审核</button>
            &nbsp;&nbsp;
            <button type="button" class="btn btn-warning" value="查看历史" id="ckls">查看记录</button>
        </div>


    </div>
</div>
</div>


@layout("/common/_curd/_container.html"){


<script type="text/javascript">
    var ctx = "${basePath}";
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";

    $(function () {
        initGrid();
        initMenuBtn("btns", "${code}");
    });

    function initGrid() {
        var grid_url = ctx + "/${code}/list";
        var _colnames = ["",
            "填报时间",
            "数量",
            "供应商",
            "采购方",
            "商品",
//            "生产日期",
//            "生产批号",
//            "检测报告编号",
//            "检测报告图片",
            "删除",
            "追溯码"
        ];
        var _colmodel = [{name: "id", hidden: true, index: "id", width: 100},

            {name: "date", index: "date", width: 100},
            {name: "num", index: "num", width: 100},
            {name: "supname", index: "supname", width: 100},
            {name: "scname", index: "scname", hidden: true, width: 100},
            {name: "pname", index: "pname", width: 100},
//            {name: "product_date", index: "product_date", width: 100},
//            {name: "product_code", index: "product_code", width: 100},
//            {name: "checks", index: "checks", hidden: true, width: 100},
//            {
//                name: "url", index: "url", hidden: true, width: 100, formatter: function (value, row, index) {
//                return '<image height="75px" width="100px" src="' + value + '"></image>';
//            }
//            },
            {
                name: "status", index: "status", width: 100, formatter: function (value, row, index) {
//                if(value === 1){
//                    return "已通过";
//                }else if(value === 2){
//                    return "未通过";
//                }else{
//                    return "未审核";
//                }
                return  '<a href="#" class="btn btn-btn btn-danger btn-xs"  onclick="deletes('+"'"+index.id+"'"+')">'+"删除"+'</a>' ;


            }
            },
            {name: "code", index: "code", hidden: true, width: 100}
        ];

        jQuery(grid_selector).jqGrid({
            url: grid_url,
            shrinkToFit: true,
            colNames: _colnames,
            colModel: _colmodel,
            jsonReader: {id: "id"},
            pager: pager_selector,
            postData: {
                sort: "id",
                where: "{buy_num:" + $('#buynum').val() + "}",
                order: "desc"
            }
        });
    }

    deletes = function (id) {
        ajaxData = {ids:id};
        $.post("/buy/remove",ajaxData,function (res) {
            jQuery("#grid-table").trigger("reloadGrid");
            $('#code').val("");
            $('#code').focus();
        });
    }
</script>
<!--<script src="${basePath}/static/laydate/laydate.js"></script>-->
<!--<script type="text/javascript">-->
    <!--laydate({-->
        <!--elem: '#date_prod',-->
        <!--format: 'YYYY-MM-DD', // 分隔符可以任意定义，该例子表示只显示年月日-->
        <!--//festival: true, //显示节日-->
        <!--choose: function (datas) { //选择日期完毕的回调-->
            <!--/*   alert('得到：'+datas); */-->
        <!--}-->
    <!--});-->


<!--</script>-->


<!-- 配置 grid -->
<div class="row">
    <div class="col-xs-12 tb-grid">
        <!-- 按钮 -->

        <!--<input type="text" id = "zdzd" autocomplete="off">-->
        <!--<div class="welljq well-sm" id="btns"></div>-->
        <!-- grid -->
        <table id="grid-table"></table>
        <!-- 分页-->
        <div id="grid-pager"></div>
    </div>
</div>

<!-- 引入所需的js -->
@include("/common/_listscript.html"){}


<script>

    $(document).ready(function () {
        $('#code').focus();
        var layerIndex = parent.layer.getFrameIndex(window.name), //获取窗口索引
                storage_clickNum = 0;
        $('#supplierName').on("click", function () {
            layer.open({
                type: 2,
                title: '选择供应商',
                shadeClose: true,
                area: ['800px', '600px'],
                content: '/suppliers/choose'//iframe的url
                ,end:function () {
                    $('#quantity').focus()
                }
            })
        })

        $('#code').on('keypress',function(event){
            if(event.keyCode == 13){
                ajaxData = {code:$('#code').val()};
                $.post("/buy/bycode",ajaxData,function (res) {
                    $('#supplierName').val(res.sname)
                    $('#supplierId').val(res.s_id)
                    $('#inputMatId').val(res.id)
                    $('#inputMatName').val(res.name)
                    $('#manufacture').val(res.factory)
                    $('#spec').val(res.unit)
                    $('#quantity').val(res.quality)
                });
            }
        });
        $('#quantity').on('keypress',function(event){
            if(event.keyCode == 13){
                $('#btn_storage').click()
            }
        });
        $('#inputMatName').on("click", function () {
            layer.open({
                type: 2,
                title: '选择商品',
                shadeClose: true,
                area: ['80%', '80%'],
                content: '/product/choose'//iframe的url
                ,end:function () {
                    $('#quantity').focus()
                }
            })
        })

        $('#ckls').on("click", function () {
           window.location.href = "/buynum"
        })




        $("#btn_storage").on("click", function () {
//            if ($('#date_prod').val() === "") {
//                layer.msg("请填写生产日期")
//                return false;
//            }
//            storage_clickNum++;
//            if (storage_clickNum <= 1) {// 限制重复点击
            var ajaxURL = $("form").attr("data-url"),
                    ajaxData = $("form").serialize();
            $.post(ajaxURL, ajaxData, function (res) {
                if (res["success"]) {
                    layer.msg("新增成功！", {
                        shift: -1, time: 200, end: function () {
                            jQuery("#grid-table").trigger("reloadGrid");
//                            $('#code').val("");
                            $('input:not(#buynum)').val("")
                            $('#code').focus();
//                                window.location.reload();
                        }
                    });
                }
            });
//            }
            setTimeout(function () {
                save_clickNum = 0;
            }, 2000);

        })

        $("#tjsh").on("click", function () {
            if ($('#buynum').val() === "") {
                layer.msg("未获取到采购单")
                return false;
            }
//            if ($('#pic').val() === "") {
//                layer.msg("你尚未上传检验报告")
//                return false;
//            }
            storage_clickNum++;
            if (storage_clickNum <= 1) {// 限制重复点击
                var ajaxURL = "/buynum/tjsh",
                        ajaxData = {
                            pic: $('#pic').val(),
                            id: $('#buynum').val()
                        };
                $.post(ajaxURL, ajaxData, function (res) {
                    if (res["success"]) {
                        layer.msg("提交成功！", {
                            shift: -1, time: 200, end: function () {
                                window.location.href = "/buynum"
                            }
                        });
                    }
                });
            }


        })
    })
</script>
@}


</body>
</html>